package com.tan.steamship.controller;

import com.tan.steamship.common.Result;
import com.tan.steamship.dto.RoutesDto;
import com.tan.steamship.service.RoutesService;
import com.tan.steamship.vo.RoutesVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @description: 航线信息
 * @author: longshifu
 * @time: 2024/12/10 22:15
 */
@RestController
@RequestMapping("/routes/v1")
public class RoutesController {
    @Autowired
    RoutesService routesService;

    /**
     * 航线列表
     *
     * @param type 类型： 1-亚洲，2-欧洲，3-非洲，4-南美洲，5-北美洲，6-大洋洲，7-南极洲，0-大热门航线，8-销量榜前10
     * @return
     */
    @GetMapping("/list")
    public Result getProductByCategoryId(@RequestParam(value = "type", required = false) Integer type,
                                         @RequestParam(value = "pageIndex", defaultValue = "1") int pageIndex,
                                         @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
        return Result.success(routesService.listRoutes(type, pageIndex, pageSize));
    }

    /**
     * 保存或修改
     *
     * @param routesDto
     * @return
     */
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody RoutesDto routesDto) {
        routesService.saveOrUpdate(routesDto);
        return Result.success();
    }

    /**
     * 详情
     *
     * @param id id
     * @return
     */
    @GetMapping("/detail")
    public Result detail(@RequestParam("id") String id) {
        RoutesVo detail = routesService.detail(id);
        return Result.success(detail);
    }

    /**
     * 删除
     *
     * @param id id
     * @return
     */
    @GetMapping("/delete")
    public Result delete(@RequestParam("id") String id) {
        routesService.removeById(id);
        return Result.success();
    }
}
